package com.nuliji.util.shiro.inter.impl;

import com.nuliji.util.shiro.AdminRealm;
import com.nuliji.util.shiro.DevelopRealm;
import com.nuliji.util.shiro.UserRealm;
import com.nuliji.tools.shiro.inter.RealmAuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by GaoJie on 2017/11/3.
 * 带Realm的登录
 */
public class RealmUsernamePasswordToken extends UsernamePasswordToken implements RealmAuthenticationToken {

    private static final Logger logger = LoggerFactory.getLogger(RealmUsernamePasswordToken.class);
    protected Class realmCls;
    @Override
    public Class getRealm() {
        return realmCls;
    }

    public RealmUsernamePasswordToken(String username, String password, Class realmCls){
        super(username, password);
        this.realmCls = realmCls;
    }

    public RealmUsernamePasswordToken(String username, String password, Boolean remember, Class realmCls){
        super(username, password, remember);
        this.realmCls = realmCls;
    }

    public static RealmUsernamePasswordToken user(String username, String password){
        logger.info("Login with User");
        return new RealmUsernamePasswordToken(username, password, UserRealm.class);
    }
    public static RealmUsernamePasswordToken admin(String username, String password){
        logger.info("Login with Admin");
        return new RealmUsernamePasswordToken(username, password, AdminRealm.class);
    }
    public static RealmUsernamePasswordToken develop(String username, String password){
        logger.info("Login with Develop");
        return new RealmUsernamePasswordToken(username, password, DevelopRealm.class);
    }

    public static RealmUsernamePasswordToken user(String username, String password, Boolean remember){
        logger.info("Login with User");
        return new RealmUsernamePasswordToken(username, password, remember, UserRealm.class);
    }
    public static RealmUsernamePasswordToken admin(String username, String password, Boolean remember){
        logger.info("Login with Admin");
        return new RealmUsernamePasswordToken(username, password, remember, AdminRealm.class);
    }
    public static RealmUsernamePasswordToken develop(String username, String password, Boolean remember){
        logger.info("Login with Develop");
        return new RealmUsernamePasswordToken(username, password, remember, DevelopRealm.class);
    }
}
